package com.econ.powercloud.ems.controller;

import com.econ.powercloud.common.base.facade.pojo.MsgResult;
import com.econ.powercloud.common.base.facade.pojo.PageResult;
import com.econ.powercloud.ems.pojo.ApiDataVO;
import com.econ.powercloud.ems.pojo.EmsEnergyStationVO;
import com.econ.powercloud.ems.pojo.requestVO.EmsEnergyStationEdit;
import com.econ.powercloud.ems.pojo.requestVO.EmsEnergyStationRequestVO;
import com.econ.powercloud.ems.pojo.requestVO.EmsStationSvgEdit;
import com.econ.powercloud.ems.pojo.requestVO.TemperatureRangeRequestVO;
import com.econ.powercloud.ems.service.biz.EnergyStationService;
import com.econ.powercloud.powernode.gateway.base.utils.CurrentUserUtil;
import com.econ.powercloud.powernode.gateway.common.domain.UserDTO;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author : zjf
 * @Description : 储能站controller
 * @Date : 2021/7/28 17:36
 * @Modified by : zjf
 */
@Api(tags = "储能站")
@RestController
@RequestMapping(value = "/api/v2/energyStation")
public class EnergyStationController extends ApiBaseController {

    @Autowired
    private EnergyStationService energyStationService;

    @ApiOperation(value = "获取某储能站详情")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "energyStationId", value = "储能站id", dataType = "String")
    })
    @GetMapping(value = "getEnergyStation")
    public MsgResult<EmsEnergyStationVO> getEnergyStation(@RequestParam(value = "energyStationId") String energyStationId){
        return successHandler(energyStationService.getEnergyStationById(energyStationId));
    }

    @ApiOperation(value = "获取储能站列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "pageNo", value = "页码", defaultValue = "1", dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "每页大小", defaultValue = "20", dataType = "int")
    })
    @GetMapping(value = "getList")
    public MsgResult<PageResult<List<EmsEnergyStationVO>>> getList(@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                                                                   @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize){
        //获取用户信息
        UserDTO userDTO = CurrentUserUtil.get();
        return successHandler(energyStationService.getList(userDTO,pageNo,pageSize));
    }

    @ApiOperation(value = "校验场景编号")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "sceneCode", value = "场景编号", dataType = "String")
    })
    @GetMapping(value = "checkSceneCode")
    public MsgResult<List<ApiDataVO>> checkSceneCode(@RequestParam(value = "sceneCode") String sceneCode){
        return successHandler(energyStationService.checkSceneCode(sceneCode));
    }

    @ApiOperation(value = "新增储能站")
    @PostMapping(value = "addStation")
    public MsgResult<String> addStation(@RequestBody @Validated EmsEnergyStationRequestVO requestVO){
        return successHandler(energyStationService.addStation(requestVO));
    }

    /**
     * 目前不支持修改场景编号
     */
    @ApiOperation(value = "修改储能站")
    @PutMapping(value = "updateStation")
    public MsgResult<String> updateStation(@RequestBody @Validated EmsEnergyStationEdit requestVO){
        energyStationService.updateStation(requestVO);
        return successHandler("修改储能站成功!");
    }

    @ApiOperation(value = "修改SVG资源")
    @PutMapping(value = "updateSvgSource")
    public MsgResult<String> updateSvgSource(@RequestBody @Validated EmsStationSvgEdit svgEdit){
        energyStationService.updateSvgSource(svgEdit);
        return successHandler("修改SVG资源成功!");
    }

    @ApiOperation(value = "修改电池簇的温度上下限")
    @PutMapping(value = "updateTemperatureRange")
    public MsgResult<String> updateSvgSource(@RequestBody @Validated TemperatureRangeRequestVO requestVO){
        energyStationService.updateTemperatureRange(requestVO.getStationId(),requestVO.getUpper(),requestVO.getLower());
        return successHandler("修改修改电池簇的温度上下限成功!");
    }

}
